package com.woniu.service.task;

import com.alibaba.fastjson2.JSON;
import com.woniu.entity.vo.TrainingVO;
import com.woniu.service.ITrainingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;
import java.util.Set;

@Configuration
@Slf4j
public class GetRecommend  {
    @Autowired
    private ITrainingService trainingService;
    @Autowired
    private RedisTemplate redisTemplate;

//    @Scheduled(cron = "0 0 */1 * * ?")
    @Scheduled(cron = "0 * * * * ?")
    public void getRecommend() {
        log.debug("定时任务获取推荐信息，存储到Redis中=====");
        Set<TrainingVO> recommendVOs=trainingService.recommend();
        //        把查询的数据存储到Redis中
        Long save = redisTemplate.opsForSet().add("recommends", recommendVOs.toArray());
        if (save>0){
            log.debug("存储成功=====");
        }
    }
}
